/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-04-27
 * Time: 14:59
 */
public class Main {
    public static void main(String[] args) {
    /*    int i = 0;
        int j = 0;
        int n = 0;
        int sum = 0;
        int k = 0;
        for (n = 100; n < 1000; n++) {
            i = n % 10;
            j = n / 10 % 10;
            k = n / 100 % 10;
            sum = i * i * i + j * j * j + k * k * k;
            if (sum == n) {
                System.out.println("1000以内水仙花数为:" + n + " ");
            }
        }*/

        /**
         * 方法二：可以求多位数的水仙花数
         */
        for (int i = 123; i < 999999; i++) {
            int tmp = 0;
            tmp = i;
            int count = 0;
            while (tmp != 0) {
                count++;
                tmp /= 10;
            }
            tmp = i;
            int sum = 0;
            while (tmp != 0) {
                sum += Math.pow(tmp % 10, count);
                tmp /= 10;
            }

            if (i == sum) {
                System.out.print(i + " ");
            }
        }
    }
}
